﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using Entidades;

namespace ProyectoCine
{
    public partial class MostrarCine : System.Web.UI.Page,IGrilla
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                ViewState["Orden"] = "";
                cargarGrilla();

                if (Session["id_Cine"] != null)
                {
                    Cine cine = CineDAO.BuscarPorId((int)Session["id_Cine"]);
                    panelCine.GroupingText = cine.Nombre;
                    lblNombre.Text = cine.Nombre;
                    lblDireccion.Text = cine.Direccion;
                    lblINumDire.Text = cine.NumDireccion.ToString();
                    lblBarrio.Text = cine.Barrio;
                    lblTelefono.Text = cine.Telefono.ToString();
                }
            }
        }

        protected void gvPeliculas_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["id_Pelicula"] = gvPeliculas.SelectedDataKey.Value;
            Response.Redirect("MostrarPelicula.aspx");
        }

        public void cargarGrilla()
        {
            gvPeliculas.DataKeyNames = new string[] { "Id_Pelicula" };
            gvPeliculas.DataSource = FuncionDAO.cargarGrillaCine((int)Session["id_Cine"],ViewState["Orden"].ToString());
            gvPeliculas.DataBind();
        }

        protected void gvPeliculas_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvPeliculas.PageIndex = e.NewPageIndex;
            cargarGrilla();
        }

        protected void gvPeliculas_Sorting(object sender, GridViewSortEventArgs e)
        {
            ViewState["Orden"] = e.SortExpression;
            cargarGrilla();
        }

        protected void btnVolver_Click(object sender, EventArgs e)
        {
            Response.Redirect("CinesDisponibles.aspx");
        }
    }
}